package pub.cleangao.memm.transport;

import pub.cleangao.memm.transport.message.RpcRequest;
import pub.cleangao.memm.transport.message.RpcResponse;

import java.net.InetSocketAddress;
import java.net.Socket;

public interface RequestTransport {

    /**
     * 请求远端服务
     */
    RpcResponse<Object> send(RpcRequest rpcRequest);

    void shutdown();

    default boolean testConnection(String host, int port) {
        InetSocketAddress inetSocketAddress = new InetSocketAddress(host, port);
        try (Socket socket = new Socket()) {
            socket.connect(inetSocketAddress);
            return true;
        } catch (Exception ignore) {
            return false;
        }
    }

}
